package com.andy.customerService.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 分页
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Page {

    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 当前页数
     */
//    @NotNull(message = "当前页不能为空")
    private Integer pageNo=1;

    /**
     * 每页显示条数
     */
//    @NotNull(message = "每页大小不能为空")
    private Integer pageSize=10;

    /**
     * 总条数
     */
    private Integer totalNum;

    /**
     * 开始条数
     */
    private Integer startNum;

    /**
     * 获取开始行数
     *
     * @return
     */
    public int getStartRow() {
        if (pageNo == 0) {
            return 0;
        }
        return (pageNo - 1) * pageSize;
    }

    /**
     * 获取总页数
     *
     * @return
     */
    public Integer getTotalPage() {

        if (getTotalNum() == null || getPageSize() == null) {
            return null;
        }
        totalPage = getTotalNum() / getPageSize();
        return (totalNum % pageSize == 0) ? totalPage : totalPage + 1;
    }

}
